﻿using System;
using HTB.DevFx.Utils;

namespace Maple.Weixin.MP.QRCode
{
    class QRCode
    {
        public const int MAX_SCENEID_FOR_LIMIT = 100000;

        public static string CreatePostJson(QRCodeType type, int expireSeconds, Int32 sceneid) {
            if (sceneid < 0)
                throw new ArgumentException("sceneid cannot be less than zero!");

            object obj = null;
            switch (type) {
                case QRCodeType.QR_LIMIT_SCENE:
                    if (sceneid > MAX_SCENEID_FOR_LIMIT)
                        throw new ArgumentException("sceneid cannot be greater than 100000!");
                    obj = new
                        {
                            action_name = type.ToString(),
                            action_info = new
                                {
                                    scene = new
                                        {
                                            scene_id = sceneid
                                        }
                                }
                        };
                    break;
                case QRCodeType.QR_SCENE:
                    obj = new
                        {
                            expire_seconds = expireSeconds,
                            action_name = type.ToString(),
                            action_info = new
                                {
                                    scene = new
                                        {
                                            scene_id = sceneid
                                        }
                                }
                        };
                    break;
            }

            return obj != null ? JsonHelper.ToJson(obj, true) : "";
        }
    }
}
